package com.taxi.driver.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.support.v7.widget.AppCompatEditText;
import android.text.TextUtils;
import android.util.AttributeSet;

import com.mikepenz.iconics.IconicsDrawable;
import com.taxi.driver.R;

/**
 * 功能描述：
 */
public class EditTextPlus extends AppCompatEditText {

    public EditTextPlus(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context, attrs, 0);
    }

    public EditTextPlus(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init(context, attrs, defStyleAttr);
    }

    private void init(Context context, AttributeSet attrs, int defStyleAttr) {
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AllDerectionIcon, defStyleAttr, 0);
        if (a == null) return;
        String icon = a.getString(R.styleable.AllDerectionIcon_left_icon);
        if (!TextUtils.isEmpty(icon)) {
            IconicsDrawable drawable = new IconicsDrawable(context, icon);
            int color = a.getColor(R.styleable.AllDerectionIcon_left_color, 0);
            int size = a.getDimensionPixelSize(R.styleable.AllDerectionIcon_left_size, -1);
            if (color != 0) drawable.color(color);
            if (size != -1) drawable.sizePx(size);
            setCompoundDrawables(drawable, null, null, null);
        }
        a.recycle();
    }

}
